package com.design.behavioral.visitor;

import org.junit.Test;

/**
 * 单分派和双份派测试
 * 编译时看左边，运行时看右边
 */
public class Client {
    /**
     * 方法重写实现动态分派
     */
    @Test
    public void fun1(){
        Animal animal = new Animal();
        animal.execute();

        animal = new Dog();
        animal.execute();

        animal = new Cat();
        animal.execute();
    }

    /**
     * 编译期间根据类型判断的静态分派
     * 编译时看左边，运行时看右边
     */
    @Test
    public void fun2(){
        Animal animal = new Animal();
        Animal dog = new Dog();
        Animal cat = new Cat();

        Execute execute = new Execute();

        execute.execute(animal);
        execute.execute(dog);
        execute.execute(cat);

    }

    /**
     * 双分派
     */
    @Test
    public void fun3(){
        Animal animal = new Animal();
        Animal dog = new Dog();
        Animal cat = new Cat();

        Execute execute = new Execute();

        animal.execute(execute);
        dog.execute(execute);
        cat.execute(execute);
    }

}
